#! /bin/bash

while read RULE_NAME && read RULE_SHORT_NAME && read SUB_RULE && read OPERATORS && read
do
echo "\
%%%%%%%%%%
%
%${RULE_NAME}(${RULE_SHORT_NAME}(X)) -->
%   ${SUB_RULE}(X1), rept(${RULE_NAME}_subexpr1, X2),
%   { X3 = [X1, X2], flatten(X3, X4) }.
%
%${RULE_NAME}_subexpr1(X) -->
%   ("

for op in ${OPERATORS} ;
do
   echo "%      oprt(${op}, X1), !;"
done


echo "\
%   ),
%   ${SUB_RULE}(X2),  
%   { X3 = [X1, X2], flatten(X3, X) }.
%
%%%%%%%%%%

"
done < data_all
